bitkeeper revision 1.963 (40cdc6e7KtOV36mP1pWf4c8GN636Pw)
authoriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>
Mon, 14 Jun 2004 15:40:23 +0000 (15:40 +0000)
committeriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>
Mon, 14 Jun 2004 15:40:23 +0000 (15:40 +0000)
readline re-fix

tools/xenctl/lib/ip.py

index bf5a6a2dff656295b4703d24bd3fa8508615b4c0..301e3654b2f12b63ad8d21ab435c67c51e5289b5 100644 (file)
@@ -5,12 +5,42 @@ import struct
 
 ##### Networking-related functions
 
+def readlines(fd):
+    """Version of readlines safe against EINTR.
+    """
+    import errno
+    
+    lines = []
+    while 1:
+        try:
+            line = fd.readline()
+        except IOError, ex:
+            if ex.errno == errno.EINTR:
+                continue
+            else:
+                raise
+        if line == '': break
+        lines.append(line)
+    return lines
+
+def readline(fd):
+    """Version of readline safe against EINTR.
+    """
+    while 1:
+        try:
+            return fd.readline()
+        except IOError, ex:
+            if ex.errno == errno.EINTR:
+                continue
+            else:
+                raise
+        
 def get_current_ipaddr(dev='eth0'):
     """Return a string containing the primary IP address for the given
     network interface (default 'eth0').
     """
     fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
-    lines = fd.readlines()
+    lines = readlines(fd)
     for line in lines:
         m = re.search( '^\s+inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
                        line )
@@ -23,7 +53,7 @@ def get_current_ipmask(dev='eth0'):
     network interface (default 'eth0').
     """
     fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' )
-    lines = fd.readlines()
+    lines = readlines(fd)
     for line in lines:
         m = re.search( '^.+Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*',
                        line )
@@ -36,7 +66,7 @@ def get_current_ipgw(dev='eth0'):
     network interface (default 'eth0').
     """
     fd = os.popen( '/sbin/route -n' )
-    lines = fd.readlines()
+    lines = readlines(fd)
     for line in lines:
         m = re.search( '^\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' +
                        '\s+\S+\s+\S*G.*' + dev + '.*', line )